package com.yyfax.pay.vo.depository;

import com.yyfax.commons.lang.DateUtil;
import com.yyfax.pay.common.exception.PayExceptionCode;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import java.util.Calendar;
import java.util.Date;

/**
 * 转账充值查询请求
 *
 * @author wujiande
 * @date 2018-05-21 17:34:20
 * @since v2.1.7
 */
public class QueryTransferChargeReq {

	/** 充值流水号 */
	private String busiId;
	/** 充值码 */
	private String chargeCode;
	/** 起始时间 */
	@NotBlank(message = "startDate不能为空")
	@Pattern(regexp = "([0-9]{4}[-][0-9]{2}[-][0-9]{2})", message = "startDate时间格式有误")
	private String startDate;
	/** 截止时间 */
	@NotBlank(message = "endDate不能为空")
	@Pattern(regexp = "([0-9]{4}[-][0-9]{2}[-][0-9]{2})", message = "endDate时间格式有误")
	private String endDate;
	/** 页码 */
	@Min(value = 1, message = "pageNo需大于0")
	private Integer pageNo;
	/** 每页条数 */
	@Range(min = 1, max = 50, message = "pageSize需在1~50之间")
	private Integer pageSize;

	/** 状态 */
	private String state;

	/**
	 * 校验
	 */
	public void validate() {
		Date start = DateUtil.str2Date(startDate);
		Date end = DateUtil.str2Date(endDate);
		Date now = DateUtil.str2Date(DateUtil.getCurrentDate());
		Calendar cal = Calendar.getInstance();
		cal.setTime(now);
		cal.add(Calendar.DATE, -30);
		if (start.before(cal.getTime()) && end.compareTo(cal.getTime()) >= 0) {
			throw PayExceptionCode.ERROR_ILL_PARAMETER.expMsg("查询范围只允许30内或30天前");
		}
	}

	public String getBusiId() {
		return busiId;
	}

	public void setBusiId(String busiId) {
		this.busiId = busiId;
	}

	public String getChargeCode() {
		return chargeCode;
	}

	public void setChargeCode(String chargeCode) {
		this.chargeCode = chargeCode;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}
}
